<template>
    <div>
        <el-card>
            <el-select v-model="value" filterable >
                <el-option
                    v-for="yearTargetOption in yearTargetOptions"
                    :key="yearTargetOption.value"
                    :label="yearTargetOption.label"
                    :value="yearTargetOption.value"
                >
                </el-option>
            </el-select>
            <el-button type="primary" style="margin-left: 5px">查询</el-button>
        </el-card>
    </div>
</template>

<script>
import yearTargetApi from '../../../../api/yearTagetApi';
export default {
    data() {
        return {
            yearTargetOptions: [],
            value: '',
            label: '',
        };
    },
    methods: {
        async getTargetYear() {
            await yearTargetApi.findAll().then((res) => {
                for (let i = 0; i < res.data.length; ++i) {
                    this.yearTargetOptions[i] = {
                        value: res.data[i].id,
                        label: res.data[i].name
                    };
                }
                this.value = this.yearTargetOptions[0].value;
                this.label = this.yearTargetOptions[0].label;
                // 强制刷新 解决有数据不渲染的问题
                this.$forceUpdate();
            });
        },
    },
    created() {
        this.getTargetYear()
    }
};
</script>

<style>
</style>